#导出数据库oems到sql.xlsx 0506 0507 v1.0
# 存储做好的产品到mysql数据库 220501
# import linecache
# print(linecache.getline("OEMs.txt",1))
# print(linecache.getline("OEMs.txt",2))
# print(linecache.getline("OEMs.txt",3))
# print(linecache.getline("OEMs.txt",4))
# print(linecache.getline("OEMs.txt",5))
# oem1=linecache.getline("OEMs.txt",1)
# oem2=linecache.getline("OEMs.txt",2)
# oem3=linecache.getline("OEMs.txt",3)
# oem4=linecache.getline("OEMs.txt",4)
# oem5=linecache.getline("OEMs.txt",5)
#oem.py
# f=open("OEMs.txt","r")
# lines=f.readlines()
#删除旧的sql.xlsx
import os
if os.path.exists("C:\\ProgramData\\MySQL\\MySQL Server 5.5\\data\\wk\\sql.xlsx"):
	os.remove("C:\\ProgramData\\MySQL\\MySQL Server 5.5\\data\\wk\\sql.xlsx")
#创建连接
import pymysql
con =pymysql.connect(
host = '127.0.0.1',
port =3306,
user = 'root',
password = 'root',
db = 'wk',
charset = 'utf8'
)
#读取oems.txt行

#插入表
#oem1-oem5
#建立游标
cur=con.cursor()
#执行sql语句 导出数据库oems到sql.xlsx

sql='SELECT*FROM oems into OUTFILE "sql.xlsx" '
cur.execute(sql)
#提交 *无参数；commit（）在con下;执行多条语句后一次性提交
con.commit()
#获取反馈
print(cur.fetchall())
#关闭连接
con.close()

os.startfile(r'C:\ProgramData\MySQL\MySQL Server 5.5\data\wk\sql.xlsx') #打开sql.xlsx